import BaseAccessControl from 'framework/accesscontrol/BaseAccessControl'
import environments from '@/util/environments';

import {TopMessage} from 'framework/util'

export default class Authentication extends BaseAccessControl {
  async run(to, from, next) {


    if (to.meta.hasOwnProperty('access') && environments.use('account').isAccess(to.meta.access) === false) {


      if (environments.use('account').isAccess(access) === false) {
        TopMessage.set({
          type: 'error',
          message: '您的权限不足'
        });
        environments.use('account').commit('clear');
        return next({path: '/login'});
      }
    }

    if (environments.use('account').isGuest() === true) {
      TopMessage.set({
        type: 'error',
        message: '凭证失效请重新登录'
      });
      return next({path: '/login'});
    }

    return next();
    // if (environments.use('account').isAccess() === false) {
    //   return next();
    // }


  }
}
